include etc/Makefile.conf

all: config
	make --no-print-directory -C $(SRC)
	make --no-print-directory -C $(LIB)

config:
	@if [ $(ETC)/Makefile.conf -ot VERSION -o \
             $(ETC)/Makefile.conf -ot configure ]; then \
          echo 'Configuration files are not up to date.' 1>&2; \
	  echo 'Please run `./configure` (with right options).' 1>&2; \
          exit 1; \
	fi

install: all
	mkdir -p "$(BINDIR)"
	mkdir -p "$(LIBDIR)"
	mkdir -p "$(MANDIR)"
	cp $(BIN)/lazy-ocaml "$(BINDIR)/lazy-ocaml"
	cp $(BIN)/fmteraser "$(BINDIR)/fmteraser"
	cp $(MAN)/lazy-ocaml.1.gz "$(MANDIR)/lazy-ocaml.1.gz"
	cp lib/*.o "$(LIBDIR)/"
	cp lib/*.a "$(LIBDIR)/"
	cp lib/*.ml "$(LIBDIR)/"
	cp lib/*.mli "$(LIBDIR)/"
	cp lib/*.cmo "$(LIBDIR)/"
	cp lib/*.cmi "$(LIBDIR)/"
	cp lib/*.cmx "$(LIBDIR)/"
	cp lib/*.cma "$(LIBDIR)/"
	cp lib/*.cmxa "$(LIBDIR)/"

uninstall:
	-rm -f "$(BINDIR)/lazy-ocaml"
	-rm -f "$(BINDIR)/fmteraser"
	-rm -f "$(MANDIR)/lazy-ocaml.1.gz"
	-rm -f "$(LIBDIR)/"*.ml
	-rm -f "$(LIBDIR)/"*.mli
	-rm -f "$(LIBDIR)/"*.cmi
	-rm -f "$(LIBDIR)/"*.cmo
	-rm -f "$(LIBDIR)/"*.cmx
	@if [ -d "$(LIBDIR)" ];then echo rmdir "$(LIBDIR)";rmdir "$(LIBDIR)";fi

etc/Makefile.conf:
	@echo "You must run ./configure before" 1>&2
	@exit 1

dist: clean
	dist/distgen

tests:
	@make --no-print-directory -C $(TESTS) tests

clean:
	@rm -f *~ */*~ */*/*~
	@make --no-print-directory -C $(TESTS) clean
	@make --no-print-directory -C $(LIB) clean
	@make --no-print-directory -C $(SRC) clean

.PHONY: all config install uninstall dist tests clean
